package com.leyou.item.mapper;

import com.leyou.common.mapper.BaseMapper;
import com.leyou.item.pojo.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author huangxin
 * @date 2019/4/19-19:55
 */
public interface BrandMapper extends BaseMapper<Brand,Long> {
    //添加中间表
    @Insert("insert into tb_category_brand(category_id,brand_id) values (#{cid},#{bid});")
    int insertCategoryBrand(@Param("cid") Long cid, @Param("bid") Long bid);

    //删除中间表
    @Delete("DELETE FROM tb_category_brand WHERE brand_id = #{bid}")
    int deleteCategoryBrandByBid( @Param("bid") Long bid);

    //根据分类id查询品牌集合
    @Select("SELECT * FROM tb_brand where id in(SELECT brand_id FROM tb_category_brand where category_id = #{cid})")
    List<Brand> selectBrandByCid(@Param("cid") Long cid);
}
